package cn.tqfeiyang.smartadmin.commons.toolbox;

import cn.hutool.cache.Cache;
import cn.hutool.cache.CacheUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.tqfeiyang.smartadmin.commons.application.SmartAdminConfig;

/**
 * 缓存工具类
 *
 * @author tqfeiyang
 * @since 2024/8/24 9:46
 */
public class CacheUtils {

    private CacheUtils() {}

    /**
     * 创建新的缓存
     *
     * @return 新缓存
     */
    public static <K,V> Cache<K, V> newCache() {
        SmartAdminConfig config = SpringUtil.getBean(SmartAdminConfig.class);
        return CacheUtil.newFIFOCache(config.getCacheCapacity(), config.getCacheTimeout());
    }
}
